﻿using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using RaGE.Properties;

namespace RaGE
{
    public partial class MainWindow : Form
    {
        [DllImport("Kernel32.dll")]
        private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, Byte[] lpBuffer, int nSize, int? lpNumberOfBytesRead);

        public MainWindow()
        {
            InitializeComponent();
            mouseMoveCheck = new Point(0, 0);
        }

        private void SetTabPage(int page)
        {
            TabFlag = page;
        }

        private int GetTabPage()
        {
            if (tabControl_Main.SelectedIndex == TabFlag)
                return TabFlag;

            SetTabPage(tabControl_Main.SelectedIndex);
            return TabFlag;
        }

        private void ShowMode()
        {
            label_EditMode.Visible = true;
            label_ModeImg.Visible = true;
        }

        private void InitMode(object sender, EventArgs e)
        {
            // Path Editor
            TabFlag = PathTab;
            PWGShopMenu(false);
            label_EditMode.Visible = false;
            label_ModeImg.Visible = false;

            // AIPolicy Editor
            if (tabControl_Main.SelectedIndex == (int) TabPage.AIPolicy)
            {
                ShowMode();
                PWGShopMenu(false);
                ElementsMenu(false);

                toolStripComboBox_Decimal.Visible = true;
                TabFlag = AIPolicyTab;
            }
            else toolStripComboBox_Decimal.Visible = false;

            switch (tabControl_Main.SelectedIndex)
            {
                // NPCGen Editor
                case (int) TabPage.NPCGen:
                    TabFlag = NPCTab;
                    ShowMode();
                    PWGShopMenu(false);
                    ElementsMenu(false);
                    
                    switch (tabControl_NPCJDPW.SelectedIndex)
                    {
                            // Jade Dynasty
                        case 0:
                            JDNPCInitialize();
                            label_ModeImg.Image = Resources.JD1;
                            ToolStripButtonJDClick(sender, e);
                            Text = Resources.RaGEEditor + Resources.Version + Common.Version;
                            JDSelected = true;
                            PWSelected = false;
                            break;

                            // Perfect World
                        case 1:
                            PWNPCInitilaize();
                            label_ModeImg.Image = Resources.PW1;
                            ToolStripButtonPWClick(sender, e);
                            Text = Resources.RaGEEditor + Resources.Version + Common.Version;
                            JDSelected = false;
                            PWSelected = true;
                            break;
                    }
                    break;

                // GShop Editor
                case (int) TabPage.GShop:
                    TabFlag = GShopTab;
                    ShowMode();
                    PWGShopMenu(true);
                    ElementsMenu(false);
                    
                    switch (tabControl_JDPWGShop.SelectedIndex)
                    {
                            // Jade Dynasty
                        case 0:
                            label_ModeImg.Image = Resources.JD1;
                            ToolStripButtonJDClick(sender, e);
                            Text = Resources.RaGEEditor + Resources.Version + Common.Version;
                            JDSelected = true;
                            PWSelected = false;
                            break;

                            // Perfect World
                        case 1:
                            label_ModeImg.Image = Resources.PW1;
                            ToolStripButtonPWClick(sender, e);
                            Text = Resources.RaGEEditor + Resources.Version + Common.Version;
                            JDSelected = false;
                            PWSelected = true;
                            break;
                    }
                    break;
                
                // Elements Editor
                case (int) TabPage.Elements:
                    TabFlag = ElementsTab;
                    label_ModeImg.Image = Resources.PW1;
                    Text = Resources.RaGEEditor + Resources.Version + Common.Version;
                    JDSelected = false;
                    PWSelected = true;

                    ShowMode();
                    PWGShopMenu(false);
                    ElementsMenu(true);
                    break;
            }
        }

        private void ExitToolStripMenuItemClick(object sender, EventArgs e)
        {
            Close();
        }

        private void ToolStripButtonQExitClick(object sender, EventArgs e)
        {
            Close();
        }

        private void MainWindowLoad(object sender, EventArgs e)
        {
            ToolStripButtonJDClick(sender, e);
            toolStripComboBox_Decimal.SelectedIndex = 0;
            Text = Resources.RaGEVersionTitle + Common.Version;
            PWGShopInitialize();
            InitializeELMenu();
        }

        private void ToolStripButtonJDClick(object sender, EventArgs e)
        {
            if (TabFlag != (decimal) TabPage.AIPolicy)
                return;

            ShowMode();

            JDSelected = true;
            PWSelected = false;
            Common.JDState = true;
            Common.PWState = false;

            label_ModeImg.Image = Resources.JD1;

            comboBox_Proc.Items.Clear();
            comboBox_Exp.Items.Clear();

            comboBox_Proc.Items.AddRange(new object[]
            {
                "Attack",
                "Cast_Skill",
                "Broadcast_Message",
                "Reset_Aggro",
                "Execute_ActionSet",
                "Disable_ActionSet",
                "Enable_ActionSet",
                "Create_Timer",
                "Delete_Timer",
                "Flee",
                "Be_Taunted",
                "Fade_Target",
                "Fade_Aggro",
                "Break",
                "NPC_Generator",
                "Summon_Mob",
                "Unknown16",
                "Set_Path",
                "Disappear",
                "N/A",
                "N/A",
                "Respawn",
                "Set_Value",
                "Add_Value",
                "N/A",
                "Set_Mob_Attribute",
                "Drop_Warsoul"
            });

            JDProcedureList();

            comboBox_Exp.Items.AddRange(new object[]
            {
                "Is_Timer_Ticking",
                "Is_HP_Less",
                "Is_Combat_Started",
                "Randomize",
                "Is_Target_Killed",
                "Is_Dead",
                "Path_To",
                "More_Than",
                "Distance_To",
                "Unknown12",
                "Unknown13",
                "Unknown14",
                "Unknown15",
                "Public_Counter",
                "Value",
                "Rank",
                "Remove_Mob",
                "Cast_Skill"
            });
        }

        private void ToolStripButtonPWClick(object sender, EventArgs e)
        {
            if (TabFlag != (decimal) TabPage.AIPolicy)
                return;

            ShowMode();

            JDSelected = false;
            PWSelected = true;
            Common.JDState = false;
            Common.PWState = true;

            label_ModeImg.Image = Resources.PW1;

            comboBox_Proc.Items.Clear();
            comboBox_Exp.Items.Clear();

            comboBox_Proc.Items.AddRange(new object[]
            {
                "Attack",
                "Cast_Skill",
                "Broadcast_Message",
                "Reset_Aggro",
                "Execute_ActionSet",
                "Disable_ActionSet",
                "Enable_ActionSet",
                "Create_Timer",
                "Delete_Timer",
                "Flee",
                "Be_Taunted",
                "Fade_Target",
                "Fade_Aggro",
                "Break",
                "NPC_Generator",
                "Initialize_Public_Counter",
                "Increment_Public_Counter",
                "Player_Aimed_NPC_Spawn",
                "Change_Path",
                "Play_Action"
            });

            PWProcedureList();

            comboBox_Exp.Items.AddRange(new object[]
            {
                "Is_Timer Ticking",
                "Is_HP_Less",
                "Is_Combat_Started",
                "Randomize",
                "Is_Target_Dead",
                "Is_Dead",
                "Public_Counter",
                "Value",
                "Is_Event?"
            });
        }

        private void OpenToolStripMenuItemClick(object sender, EventArgs e)
        {
            switch (GetTabPage())
            {
                // ************************************************************************
                // **                         AIPolicy Editor                            **
                // ************************************************************************
                case (int)TabPage.AIPolicy:
                    ShowMode();
                    TabFlag = AIPolicyTab;

                    var openAIPolicy = new OpenFileDialog();
                    openAIPolicy.Filter = Resources.AIPolicyFilter;
                    openAIPolicy.Title = Resources.SelectAIPolicy;
                    openAIPolicy.FileName = "aipolicy.data";

                    if (openAIPolicy.ShowDialog() != DialogResult.OK || !File.Exists(openAIPolicy.FileName)) return;

                    try
                    {
                        Cursor = Cursors.WaitCursor;
                        listBox_Controller.Items.Clear();
                        listBox_ActionSet.Items.Clear();
                        textBox_Condition.Clear();
                        listBox_Procedure.Items.Clear();

                        var fileStream = File.OpenRead(openAIPolicy.FileName);
                        var binaryReader = new BinaryReader(fileStream);
                        AI = new AIPolicy();

                        AI.Signature = binaryReader.ReadInt32();
                        AI.ActionControllerCount = binaryReader.ReadInt32();
                        AI.ActionController = new ActionController[AI.ActionControllerCount];

                        for (var i = 0; i < AI.ActionController.Length; i++)
                        {
                            AI.ActionController[i] = new ActionController();

                            AI.ActionController[i].Signature = binaryReader.ReadInt32();
                            AI.ActionController[i].ID = binaryReader.ReadInt32();
                            AI.ActionController[i].ActionSetsCount = binaryReader.ReadInt32();

                            AI.ActionController[i].ActionSet = new ActionSet[AI.ActionController[i].ActionSetsCount];
                            listBox_Controller.Items.Add(AI.ActionController[i].ID.ToString(CultureInfo.InvariantCulture));

                            for (var j = 0; j < AI.ActionController[i].ActionSet.Length; j++)
                            {
                                AI.ActionController[i].ActionSet[j] = new ActionSet();

                                AI.ActionController[i].ActionSet[j].Version = binaryReader.ReadInt32();
                                var version = AI.ActionController[i].ActionSet[j].Version;

                                AI.ActionController[i].ActionSet[j].ID = binaryReader.ReadInt32();
                                AI.ActionController[i].ActionSet[j].Flags = binaryReader.ReadBytes(3);
                                AI.ActionController[i].ActionSet[j].ActionSetName = binaryReader.ReadBytes(128);

                                // ******** Jade Dynasty
                                if (JDSelected)
                                {
                                    AI.ActionController[i].ActionSet[j].Condition = LoadCondition(binaryReader);
                                    AI.ActionController[i].ActionSet[j].ProcedureCount = binaryReader.ReadInt32();
                                    AI.ActionController[i].ActionSet[j].Procedure =
                                        new Procedure[AI.ActionController[i].ActionSet[j].ProcedureCount];

                                    for (var k = 0; k < AI.ActionController[i].ActionSet[j].Procedure.Length; ++k)
                                    {
                                        AI.ActionController[i].ActionSet[j].Procedure[k] = new Procedure
                                        {
                                            Type =
                                                binaryReader.
                                                ReadInt32()
                                        };

                                        var procedure = AI.ActionController[i].ActionSet[j].Procedure[k];
                                        var objArray =
                                            JDReadParameters(AI.ActionController[i].ActionSet[j].Procedure[k].Type,
                                                             binaryReader, version);
                                        procedure.Parameter = objArray;
                                        AI.ActionController[i].ActionSet[j].Procedure[k].Target =
                                            binaryReader.ReadInt32();
                                    }
                                }

                                // ******** Perfect World
                                if (!PWSelected) continue;

                                AI.ActionController[i].ActionSet[j].Condition = LoadCondition(binaryReader);
                                AI.ActionController[i].ActionSet[j].ProcedureCount = binaryReader.ReadInt32();
                                AI.ActionController[i].ActionSet[j].Procedure =
                                    new Procedure[AI.ActionController[i].ActionSet[j].ProcedureCount];

                                for (var k = 0; k < AI.ActionController[i].ActionSet[j].Procedure.Length; ++k)
                                {
                                    AI.ActionController[i].ActionSet[j].Procedure[k] = new Procedure();

                                    AI.ActionController[i].ActionSet[j].Procedure[k].Type = binaryReader.ReadInt32();
                                    AI.ActionController[i].ActionSet[j].Procedure[k].Parameter =
                                        PWReadParameters(AI.ActionController[i].ActionSet[j].Procedure[k].Type,
                                                         binaryReader);
                                    AI.ActionController[i].ActionSet[j].Procedure[k].Target = binaryReader.ReadInt32();

                                    if (AI.ActionController[i].ActionSet[j].Procedure[k].Target == 6)
                                    {
                                        AI.ActionController[i].ActionSet[j].Procedure[k].TargetParams =
                                            PWReadTargetParameters(
                                                AI.ActionController[i].ActionSet[j].Procedure[k].Target, binaryReader);
                                    }
                                }
                            }
                        }
                        binaryReader.Dispose();
                        fileStream.Dispose();

                        Cursor = Cursors.Default;
                        openAIPolicy.Dispose();
                    }
                    catch (Exception aipEx)
                    {
                        Cursor = Cursors.Default;
                        MessageBox.Show(Resources.ErrLoadAIPolicy + aipEx.Message);
                    }
                    break;

                // ************************************************************************
                // **                            Path Editor                             **
                // ************************************************************************
                case (int)TabPage.Path:
                    InitMode(sender, e);
                    TabFlag = PathTab;

                    var openPath = new OpenFileDialog();
                    openPath.Filter = Resources.PathFilter;
                    openPath.Title = Resources.SelectPath;
                    openPath.FileName = "path.data";

                    if (openPath.ShowDialog() != DialogResult.OK || !File.Exists(openPath.FileName)) return;

                    var pathStream = File.OpenRead(openPath.FileName);
                    var pathReader = new BinaryReader(pathStream);

                    header = pathReader.ReadBytes(4);
                    count = pathReader.ReadInt32();

                    msg.Text = Resources.Total + count.ToString(CultureInfo.InvariantCulture) + Resources.Records;

                    for (var i = 0; i < count; i++)
                    {
                        var pathObject = new PathObject();
                        pathObject.ID = pathReader.ReadInt32();
                        pathObject.NameLen = pathReader.ReadInt32();
                        pathObject.Name = pathReader.ReadBytes(pathObject.NameLen);

                        path.Add(pathObject);

                        listView_Path.Items.Add(new ListViewItem(new[]
                        {
                            pathObject.ID.ToString(CultureInfo.InvariantCulture),
                            Encoding.GetEncoding("GBK").GetString(pathObject.Name)
                        }));

                        listView_Path.Items[listView_Path.Items.Count - 1].EnsureVisible();
                    }
                    break;

                // ************************************************************************
                // **                           NPCGen Editor                            **
                // ************************************************************************
                case (int)TabPage.NPCGen:
                    TabFlag = NPCTab;

                    // ******** Perfect World
                    if (PWSelected)
                    {
                        ShowMode();

                        var openNPC = new OpenFileDialog();
                        openNPC.Filter = Resources.NPCGenFilter;

                        if(openNPC.ShowDialog() == DialogResult.OK && File.Exists(openNPC.FileName))
                        {
                            try
                            {
                                Cursor = Cursors.AppStarting;
                                ProgressBar.Style = ProgressBarStyle.Marquee;

                                var npcStream = File.OpenRead(openNPC.FileName);
                                var npcReader = new BinaryReader(npcStream);

                                pwnpcgen = new PWNPCGen();
                                pwnpcgen.version = npcReader.ReadInt32();
                                pwnpcgen.creature_sets_count = npcReader.ReadInt32();
                                pwnpcgen.resource_sets_count = npcReader.ReadInt32();

                                if (pwnpcgen.version == 10 || JDSelected)
                                {
                                    pwnpcgen.dynamics_count = npcReader.ReadInt32();
                                    pwnpcgen.triggers_count = npcReader.ReadInt32();
                                }
                                else
                                {
                                    pwnpcgen.dynamics_count = 0;
                                    pwnpcgen.triggers_count = 0;
                                }

                                PWLoadCreatures(npcReader);
                                PWLoadResources(npcReader);
                                PWLoadDynamics(npcReader);
                                PWLoadTriggers(npcReader);

                                npcReader.Close();
                                npcStream.Close();

                                Text = Resources.RaGEEditor + Resources.Version + Common.Version + Resources.LSParen + openNPC.FileName + Resources.RPAREN;
                                ProgressBar.Style = ProgressBarStyle.Continuous;
                                Cursor = Cursors.Default;

                            }
                            catch (Exception npcEx)
                            {
                                MessageBox.Show(Resources.ErrLoadNPC + npcEx.Message);
                                ProgressBar.Style = ProgressBarStyle.Continuous;
                                Cursor = Cursors.Default;
                            }
                        }
                    }

                    // ******* Jade Dynasty
                    if (JDSelected)
                    {
                        ShowMode();

                        var openNPC = new OpenFileDialog();
                        openNPC.Filter = Resources.NPCGenFilter;

                        if(openNPC.ShowDialog() == DialogResult.OK && File.Exists(openNPC.FileName))
                        {
                            try
                            {
                                Cursor = Cursors.AppStarting;
                                ProgressBar.Style = ProgressBarStyle.Marquee;

                                var npcStream = File.OpenRead(openNPC.FileName);
                                var npcReader = new BinaryReader(npcStream);

                                jdnpcgen = new JDNPCGen();
                                jdnpcgen.version = npcReader.ReadInt32();
                                jdnpcgen.creature_sets_count = npcReader.ReadInt32();
                                jdnpcgen.resource_sets_count = npcReader.ReadInt32();
                                jdnpcgen.dynamics_count = npcReader.ReadInt32();
                                jdnpcgen.triggers_count = npcReader.ReadInt32();

                                JDLoadCreatures(npcReader);
                                JDLoadResources(npcReader);
                                JDLoadDynamics(npcReader);
                                JDLoadTriggers(npcReader);

                                npcReader.Close();
                                npcStream.Close();

                                Text = Resources.RaGEEditor + Resources.Version + Common.Version + Resources.LSParen + openNPC.FileName + Resources.RPAREN;
                                ProgressBar.Style = ProgressBarStyle.Continuous;
                                Cursor = Cursors.Default;
                            }
                            catch (Exception npcEx)
                            {
                                MessageBox.Show(Resources.ErrLoadNPC + npcEx.Message);
                                ProgressBar.Style = ProgressBarStyle.Continuous;
                                Cursor = Cursors.Default;
                            }
                        }
                    }

                    break;

                // ************************************************************************
                // **           GShop Editor (Uses different Open File system)           **
                // ************************************************************************
                case (int)TabPage.GShop:
                    TabFlag = GShopTab;

                    if (PWSelected)
                    {
                        return;
                    }
                    if (JDSelected)
                    {
                        MessageBox.Show(Resources.NotSupported);
                    }
                    break;

                // ************************************************************************
                // **                          Elements Editor                           **
                // ************************************************************************
                case (int)TabPage.Elements:
                    TabFlag = ElementsTab;

                    break;
            }
        }

        // Open Redirect
        private void ToolStripButtonOpenClick(object sender, EventArgs e)
        {
            switch (TabFlag)
            {
                case GShopTab:
                    MessageBox.Show(Resources.UseFileMenuGShop);
                    break;

                case ElementsTab:
                    MessageBox.Show(Resources.UseFileMenuElements);
                    break;
            }

            OpenToolStripMenuItemClick(sender, e);
        }

        private void SaveToolStripMenuItemClick(object sender, EventArgs e)
        {
            switch (GetTabPage())
            {
                // ************ AIPolicy Editor ************
                case (int)TabPage.AIPolicy:
                    var saveAIPolicy = new SaveFileDialog();
                    saveAIPolicy.InitialDirectory = Environment.CurrentDirectory;
                    saveAIPolicy.Filter = Resources.AIPolicyFilter;
                    if (AI == null || saveAIPolicy.ShowDialog() != DialogResult.OK || saveAIPolicy.FileName == "") return;

                    Cursor = Cursors.WaitCursor;

                    var aipStream = new FileStream(saveAIPolicy.FileName, FileMode.Create, FileAccess.Write);
                    var aipWriter = new BinaryWriter(aipStream);

                    aipWriter.Write(AI.Signature);
                    aipWriter.Write(AI.ActionControllerCount);

                    foreach (var actionController in AI.ActionController)
                    {
                        aipWriter.Write(actionController.Signature);
                        aipWriter.Write(actionController.ID);
                        aipWriter.Write(actionController.ActionSetsCount);

                        foreach (var actionSet in actionController.ActionSet)
                        {
                            var version = actionSet.Version;
                            aipWriter.Write(actionSet.Version);
                            aipWriter.Write(actionSet.ID);
                            aipWriter.Write(actionSet.Flags);
                            aipWriter.Write(actionSet.ActionSetName);

                            // Jade Dynasty
                            if (JDSelected) JDSaveCondition(actionSet.Condition, aipWriter);

                            // Perfect World
                            if (PWSelected) PWSaveCondition(actionSet.Condition, aipWriter);

                            aipWriter.Write(actionSet.ProcedureCount);

                            foreach (var procedure in actionSet.Procedure)
                            {
                                aipWriter.Write(procedure.Type);

                                // Jade Dynasty
                                if (JDSelected)
                                {
                                    JDWriteParameters(procedure.Type, procedure.Parameter, aipWriter, version);
                                    aipWriter.Write(procedure.Target);
                                }

                                // Perfect World
                                if (!PWSelected) continue;
                                PWWriteParameters(procedure.Type, procedure.Parameter, aipWriter);
                                aipWriter.Write(procedure.Target);
                                if (procedure.Target == 6) aipWriter.Write((int)procedure.TargetParams[0]);
                            }
                        }
                    }

                    aipWriter.Close();
                    aipStream.Close();
                    saveAIPolicy.Dispose();
                    
                    ProgressBar.Style = ProgressBarStyle.Continuous;
                    Cursor = Cursors.Default;
                    MessageBox.Show(Resources.FileSaved);

                    break;

                // ************ Path Editor ************
                case (int)TabPage.Path:
                    var savePath = new SaveFileDialog();
                    savePath.InitialDirectory = Environment.CurrentDirectory;
                    savePath.Filter = Resources.PathFilter;

                    if (savePath.ShowDialog() != DialogResult.OK) return;

                    Cursor = Cursors.WaitCursor;

                    var pStream = File.OpenWrite(savePath.FileName);
                    var pWriter = new BinaryWriter(pStream);

                    pWriter.Write(header);
                    pWriter.Write(path.Count);
                    
                    foreach (var t in path)
                    {
                        pWriter.Write(t.ID);
                        pWriter.Write(t.Name.Length);
                        pWriter.Write(t.Name);
                    }
                    
                    pWriter.Flush();
                    pWriter.Close();
                    pStream.Close();
                    savePath.Dispose();
                    
                    ProgressBar.Style = ProgressBarStyle.Continuous;
                    Cursor = Cursors.Default;
                    MessageBox.Show(Resources.FileSaved);

                    break;

                // ************ NPCGen Editor ************
                case (int)TabPage.NPCGen:
                    var save = new SaveFileDialog();
                    save.InitialDirectory = Environment.CurrentDirectory;
                    save.Filter = Resources.NPCGenFilter;

                    if (save.ShowDialog() == DialogResult.OK && save.FileName != "")
                    {
                        try
                        {
                            Cursor = Cursors.AppStarting;
                            ProgressBar.Style = ProgressBarStyle.Marquee;

                            var fs = new FileStream(save.FileName, FileMode.Create, FileAccess.Write);
                            var bw = new BinaryWriter(fs);

                            // Jade Dynasty
                            if (JDSelected)
                            {
                                bw.Write(jdnpcgen.version); //npcgen.version
                                bw.Write(jdnpcgen.creature_sets_count);
                                bw.Write(jdnpcgen.resource_sets_count);
                                bw.Write(jdnpcgen.dynamics_count);
                                bw.Write(jdnpcgen.triggers_count);

                                JDSaveCreatures(bw);
                                JDSaveResources(bw);
                                JDSaveDynamics(bw);
                                JDSaveTriggers(bw);
                            }

                            // Perfect World
                            if (PWSelected)
                            {
                                bw.Write(pwnpcgen.version); //npcgen.version
                                bw.Write(pwnpcgen.creature_sets_count);
                                bw.Write(pwnpcgen.resource_sets_count);
                                bw.Write(pwnpcgen.dynamics_count);
                                bw.Write(pwnpcgen.triggers_count);

                                PWSaveCreatures(bw);
                                PWSaveResources(bw);
                                PWSaveDynamics(bw);
                                PWSaveTriggers(bw);
                            }

                            bw.Close();
                            fs.Close();

                            ProgressBar.Style = ProgressBarStyle.Continuous;
                            Cursor = Cursors.Default;
                            MessageBox.Show(Resources.FileSaved);
                        }
                        catch
                        {
                            MessageBox.Show(Resources.ErrSaveNPC);
                            ProgressBar.Style = ProgressBarStyle.Continuous;
                            Cursor = Cursors.Default;
                        }
                    }
                    break;
                
                // ************ GShop Editor (Uses different Save File system) ************
                case (int)TabPage.GShop:
                    break;
            }
        }

        // Save Redirect
        private void ToolStripButtonSaveClick(object sender, EventArgs e)
        {
            SaveToolStripMenuItemClick(sender, e);
        }

        private void AboutRaGEEditor(object sender, EventArgs e)
        {
            (new About()).Show();
        }
        
    }
}
